#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

int main () {
  FIO("bishop");
  ios::sync_with_stdio(0), cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (n == 1) {
    cout << "1\n1 1\n";
    exit(0);
  }
  vector<pair<int, int>> ns;
  if (n == m) {
    L (i, 1, n - 1) {
      ns.eb(1, i);
      ns.eb(n, i);
    }
  } else {
    bool rev = false;
    if (n > m) {
      swap(n, m);
      rev = true;
    }
    L (i, 1, n) {
      ns.eb(i, 1);
      ns.eb(i, m);
    }
    int x = (n + 1) >> 1;
    if (n & 1) {
      L (i, x + 1, m - x) {
        ns.eb(x, i);
      }
    } else {
      for (int i = x + 2; i <= m - x - 1; i += 2) {
        ns.eb(x, i);
        ns.eb(x + 1, i);
      }
    }
    if (rev) {
      for (auto &[x, y] : ns) {
        swap(x, y);
      }
    }
  }
  cout << ns.size() << '\n';
  for (auto [x, y] : ns) {
    cout << x << ' ' << y << '\n';
  }
}
// I love WHQ!